package my.app;
 
import java.util.ArrayList;

import my.app.company.Company;
import my.app.company.CompanyOverlay;
import my.app.company.MyOverlay;
import my.app.taxi.Taxi;
import my.app.taxi.TaxiOverlay;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.MapView.LayoutParams;  
 
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
 
public class MapTabView extends MapActivity 
{    
    MapView mapView;
    MapController mapController;
    ServiceClient client;
 
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.map_tab_view);
 
        //variables
        client = ServiceClient.getInstance(getApplicationContext());
        mapView = (MapView) findViewById(R.id.mapView);
        mapController = mapView.getController();
        LinearLayout zoomLayout = (LinearLayout)findViewById(R.id.zoom);  
        View zoomView = mapView.getZoomControls(); 
        
        
        //Adding zoom widget to map.
        zoomLayout.addView(zoomView, 
            new LinearLayout.LayoutParams(
                LayoutParams.WRAP_CONTENT, 
                LayoutParams.WRAP_CONTENT)); 
        mapView.displayZoomControls(true);
        
        //Setting on maps
        mapView.getOverlays().clear();
        mapController.setZoom(15);
        
        
        //Adding taxi to map.
        ArrayList<Taxi> listTaxi = client.getAvailableTaxi();
        for (Taxi t : listTaxi) {
        	mapView.getOverlays().add(new TaxiOverlay(t));
        }
        
        //Adding companies to map.
        ArrayList<Company> listCompanies = client.getAvailableCompanies();
        for (Company c : listCompanies) {
        	mapView.getOverlays().add(new CompanyOverlay(c));
        }
        
        double ltt = Settings.getInstance().getLat();
        double lnn = Settings.getInstance().getLon();
        int lt1 = (int) (ltt * 1E6);
        int ln1 = (int) (lnn * 1E6);
        GeoPoint myp = new GeoPoint(lt1,ln1);
        mapView.getOverlays().add(new MyOverlay(myp));
        mapController.animateTo(myp);
        
        
        
        mapView.invalidate();
 
    }
 
    @Override
    protected boolean isRouteDisplayed() {
        // TODO Auto-generated method stub
        return false;
    }
}